package com.ebook.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Calendar;

/**
 * Created by IntelliJ IDEA.
 * User: liuys
 * Date: 11-7-25
 * Time: 下午9:36
 * To change this template use File | Settings | File Templates.
 */
public class TimeBaseAccessInterceptor extends HandlerInterceptorAdapter{
    private int openTime;
    private int closeTime;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if(hour>openTime && hour<=closeTime)
            return true;
        else{
            response.sendRedirect("index.jsp");
            return false;
        }
    }

    public void setOpenTime(int openTime) {
        this.openTime = openTime;
    }

    public void setCloseTime(int closeTime) {
        this.closeTime = closeTime;
    }
}
